package com.os.opencv.java.chapter3;

import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

import java.util.ArrayList;
import java.util.List;

public class Draw2 {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //用于绘制图形的背景图
        Mat img = Imgcodecs.imread("000176_grey.png");
        Scalar black = new Scalar(0, 0, 0);
        Scalar white = new Scalar(255, 255, 255);

        //多边形的点集合
        Point[] pt1 = new Point[5];
        pt1[0] = new Point(440, 540);
        pt1[1] = new Point(570, 470);
        pt1[2] = new Point(810, 420);
        pt1[3] = new Point(640, 540);
        pt1[4] = new Point(450, 580);

        //绘制鱼的轮廓
        MatOfPoint p = new MatOfPoint(pt1);
        List<MatOfPoint> pts = new ArrayList<>();
        pts.add(p);
        Imgproc.polylines(img, pts, true, white, 2);

        //绘制叶子轮廓
        Imgproc.ellipse(img, new Point(525, 130), new Size(110, 130), 95, 0.0, 360.0, white, 2);

        //在图像上绘制文字
        Imgproc.putText(img, "Fish!", new Point(560, 520), Imgproc.FONT_HERSHEY_SIMPLEX, 1, black, 2);;

        //在屏幕上显示绘制好的图像
        HighGui.imshow("img", img);
        HighGui.waitKey(0);
        System.exit(0);



    }
}
